import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class GeneratorCharaterTest {

	public static void generateCharacters(OutputStream out)
			throws IOException {
		int firstPrintableCharacter = 33;
		int numberOfPrintableCharacters = 94;
		int numberOfPerLine = 72;
		int start = firstPrintableCharacter;
		int cout = 1000;
		int n = 0;
		while (n++ < cout) {
			for (int i = start; i < start + numberOfPerLine; i++)
				out.write((i - firstPrintableCharacter) % numberOfPrintableCharacters + firstPrintableCharacter);
			out.write('\r');
			out.write('\n');
			start = (start + 1 - firstPrintableCharacter) % numberOfPrintableCharacters + firstPrintableCharacter;
		}
	}

	public static void generateCharactersWithBytes(OutputStream out)
			throws IOException {
		int firstPrintableCharacter = 33;
		int numberOfPrintableCharacters = 94;
		int numberOfPerLine = 72;
		int start = firstPrintableCharacter;
		int cout = 1000;
		int n = 0;
		byte[] line = new byte[numberOfPerLine + 2];
		while (n++ < cout) {
			for (int i = start; i < start + numberOfPerLine; i++)
				line[i - start] = (byte) ((byte) (i - firstPrintableCharacter) % numberOfPrintableCharacters
						+ firstPrintableCharacter);
			line[72] = (byte) '\r';
			line[73] = (byte) '\n';
			out.write(line);
			start = (start + 1 - firstPrintableCharacter) % numberOfPrintableCharacters + firstPrintableCharacter;
		}
	}

	public static void main(String[] args) 
			throws IOException {
		long characterBegin = System.currentTimeMillis();
		FileOutputStream fout1 = new FileOutputStream("test1.txt");
		GeneratorCharaterTest.generateCharacters(fout1);
		long characterEnd = System.currentTimeMillis();
		System.out.println("不使用byte数组：   " + (characterEnd - characterBegin));

		long byteBegin = System.currentTimeMillis();
		FileOutputStream fout2 = new FileOutputStream("test2.txt");
		GeneratorCharaterTest.generateCharactersWithBytes(fout2);
		long byteEnd = System.currentTimeMillis();
		System.out.println("使用byte数组：  " + (byteEnd - byteBegin));
	}
}
